<?php
declare (strict_types=1);

namespace app\listener\pay;

use app\event\PaySuccess;
use app\model\BaseSupplier;
use app\model\PayLog;
use think\Exception;
use think\facade\Log;

class PaySuccessAddSupplierOrderNum
{
    /**
     * 供应商添加已支付订单
     * @param PaySuccess $event
     * @return mixed
     */
    public function handle($event)
    {
        $payLog = $event->obj;

        if (!($payLog instanceof PayLog)) {
            //无需处理非  pay log
            return true;
        }

        try {

            BaseSupplier::query()
                ->where('id', $payLog->couponOrder->supplier_id)
                ->inc('order_count', 1)
                ->update();


        } catch (Exception $exception) {
            Log::error('支付成功处理供应商添加订单错误' . $exception->getMessage());
        }


    }
}
